import { createStore } from 'vuex';

// 定义状态
const state = {
  count: 0,
  message: '初始消息',
};

// 定义 mutations
const mutations = {
  increment(state) {
    state.count++;
  },
  setMessage(state, newMessage) {
    state.message = newMessage;
  },
};

// 定义 actions
const actions = {
  incrementAsync({ commit }) {
    setTimeout(() => {
      commit('increment');
    }, 1000);
  },
  updateMessage({ commit }, newMessage) {
    commit('setMessage', newMessage);
  },
};

// 定义 getters
const getters = {
  doubleCount(state) {
    return state.count * 2;
  },
};

const store = createStore({
  state,
  mutations,
  actions,
  getters,
});

export default store;